package workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import constant.Constant;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setPort(Constant.PORT);
        connectionFactory.setVirtualHost(Constant.VIRTUAL_HOST);
        connectionFactory.setUsername(Constant.USER_NAME);
        connectionFactory.setPassword(Constant.PASSWORD);
        connectionFactory.setHost(Constant.HOST);
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        //声明交换机
        channel.queueDeclare(Constant.USER_NAME,false,false,false,null);
        //发送消息
        for (int i = 0; i < 10; i++) {
            String msg="发送消息"+i;
            channel.basicPublish("",Constant.VIRTUAL_HOST,null,msg.getBytes());
        }
    }
}
